<template>
  <div class="content">
    <dt-search ref="search" :label-width="80">
      <Button type="primary" @click='onExport'>导出记录</Button>
    </dt-search>
    
    <dt-grid ref="table" page :onFetch='onFetch' />
  </div>
</template>

<script>
  import Search from './opt/Search.js'
  import Column from './opt/recordColumn.js'
  import outMgr from '@/biz/user/out'
  
  export default {
    data() {
      return {
        search: {}
      }
    },
    mounted() {
      this.$refs.table.init(this, new Column())
      this.$refs.search.init(this.$refs.table, new Search())
      this.$refs.table.fetch()
    },
    methods: {
      onFetch(data) {
        this.search = data
        return outMgr.adjustRecord(data)
      },
      onExport() {
        let s = { ...this.search },
            exportFlag = false
        if (
          (s.outOrgIds && s.outOrgIds.length > 0) || (s.inOrgIds && s.inOrgIds.length > 0)
          || s.workNo || s.name || s.phone || (s.roleIds && s.roleIds.length > 0)
          || s.validate || (s.startDate && s.endDate)
        ) {
          exportFlag = true
        }
        delete s.current
        delete s.page
        delete s.rows
        outMgr.exportRecord({
          ...s,
          exportFlag
        })
      },
    },
  }
</script>
<style lang='scss' scoped>
  .content {
    padding: 20px;
  }
</style>